#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

__global__ void convertkernelChar4ToInt(char *cbuf, 
								  int totalItem, 
								  int *output)
{
	int i = threadIdx.x + blockIdx.x * blockDim.x;

	while(i < totalItem){
				
		unsigned int x = 
			(cbuf[(i*4)] & 0xFF) | 
			((cbuf[(i*4) + 1] & 0xFF) << 8) | 
			((cbuf[(i*4) + 2] & 0xFF) << 16) | 
			((cbuf[(i*4) + 3] & 0xFF) << 24);

		output[i]= x;

		i += blockDim.x * gridDim.x;

	}

}

__global__ void convertkernelIntToChar4(int *ibuf, 
										int totalItem, 
										char *output)
{
	int i = threadIdx.x + blockIdx.x * blockDim.x;

	while(i < totalItem) {

		output[(i*4)] = (char) (ibuf[i] & (0xFF));
		output[(i*4)+1] = (char) ((ibuf[i] >> 8) & 0xFF);
		output[(i*4)+2] = (char) ((ibuf[i] >> 16) & 0xFF);
		output[(i*4)+3] = (char) ((ibuf[i] >> 24) & 0xFF);

		i += blockDim.x * gridDim.x;
	}

};